var express = require('express');
var info_center_router = express.Router();
// let Articles = require("../mongodb/mongodb").Articles //引入数据库模型
let {
  realtime_infos,//实时资讯
  policies,//政策
  subjects,//课程文章
} = require("../mongodb/mongodb")
//实时资讯
info_center_router.get('/realtime_infos', function(req, res, next) {
  let DB = realtime_infos;
  let _id = req.query._id;
  console.log("查询id为："+_id+"实时资讯")
  if(_id!=null){
    DB.find({_id:_id}).exec(function(err,docs){
      if(err){
        console.log(err)
        console.log("错误");
        res.send({
          status:300,
          msg:'暂时没有新的数据'
        })
      }else{
        res.send(docs)
      }
    }) 
  }else{
    res.send("where is your id？")
  }

});

//政策资讯
info_center_router.get('/subjects', function(req, res, next) {
  let DB = subjects;
  let _id = req.query._id;
  console.log("查询id为："+_id+"课程资讯")
  if(_id!=null){
    DB.find({_id:_id}).exec(function(err,docs){
      if(err){
        console.log(err)
        console.log("错误");
        res.send({
          status:300,
          msg:'暂时没有新的数据'
        })
      }else{
        res.send(docs)
      }
    }) 
  }else{
    res.send("where is your id？")
  } 
});

//课程资讯
info_center_router.get('/policies', function(req, res, next) {
  let DB = policies;
  let _id = req.query._id;
  console.log("查询id为："+_id+"政策资讯")
  if(_id!=null){
    DB.find({_id:_id}).exec(function(err,docs){
      if(err){
        console.log(err)
        console.log("错误");
        res.send({
          status:300,
          msg:'暂时没有新的数据'
        })
      }else{
        res.send(docs)
      }
    }) 
  }else{
    res.send("where is your id？")
  } 
});

module.exports = info_center_router;

